<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item>
      <h3>福利获取区域</h3>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="经度">
          <el-input v-model="form.x"></el-input>
        </el-form-item>
        <el-form-item label="纬度">
          <el-input v-model="form.y"></el-input>
        </el-form-item>
        <el-form-item label="福利获取半径" label-width="100px">
          <input type="text" v-model="form.scope" />
          <span>米</span>
        </el-form-item>
        <el-form-item>
          <baidu-map class="map" :center="circlePath.center" :zoom="15" :scroll-wheel-zoom="true">
            <bm-circle
              :center="circlePath.center"
              :radius="circlePath.radius"
              stroke-color="blue"
              :stroke-opacity="0.5"
              :stroke-weight="2"
              @lineupdate="updateCirclePath"
              :editing="true"
            ></bm-circle>
          </baidu-map>
        </el-form-item>
      </el-form>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">保存</el-button>
      <el-button @click="$router.push({path: '/edit/coursewelfare'})">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { searchBuy, submitScope } from "@/api/course/courseDetail";
export default {
  data() {
    return {
      form: {},
      cash: false,
      chit: false,
      circlePath: {
        center: {
          lng: 0,
          lat: 0
        },
        radius: 0
      }
    };
  },
  created() {
    searchBuy(2).then(res => {
      this.form = res.data.data;
      this.circlePath.center.lng = this.form.x;
      this.circlePath.center.lat = this.form.y;
      this.circlePath.radius = this.form.scope;
    });
  },
  methods: {
    updateCirclePath(e) {
      this.circlePath.center = e.target.getCenter();
      this.circlePath.radius = e.target.getRadius();
    },
    onSubmit() {
      submitScope(this.form).then(res => {
        this.$message({
          message: "编辑成功",
          type: "success"
        });
        this.$router.push({path: '/edit/coursewelfare'})
      });
    }
  }
};
</script>

<style>
.map {
  width: 700px;
  height: 300px;
}
</style>
